package nix.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 统计访问量
 * 
 * @author berry
 * 
 */
public class HServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		ServletContext application = this.getServletContext();
		Integer count = (Integer) application.getAttribute("count");

		if (count == null) {
			application.setAttribute("count", 1);
			count = 1;
		} else {
			application.setAttribute("count", count + 1);
		}

		PrintWriter pw = response.getWriter();
		pw.write("<h1>" + count + "</h1>");
		pw.flush();
		pw.close();
	}
}
